package com.example.demo.stu02;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;


@Service
public class ReadConfig {
    @Autowired
    private Environment environment;

    public void print(){
        //获取key值
        String name = environment.getProperty("app.name");


        //判断key是否存在
        if( environment.containsProperty("app.woner")){
            System.out.println("app.woner是存在的");
        }



        //读取key的值，转化为期望的类型，并且附上默认值
        Integer port = environment.getProperty("app.port",Integer.class,9901);

        String str = String.format("read is key : name = %s  , port = %d",name,port);
        System.out.println("str = "+ str);

    }


}
